package com.shundr.truck.http;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.shundr.auth.frame.util.JsonUtil;
import com.shundr.truck.model.TruckInfo;

/**
 * 用户车辆
 * 
 * @author Administrator
 *
 */
public class UserTruckParser {

	/**
	 * 
	 * parserCargoList(这里用一句话描述这个方法的作用) 解析货源列表 (这里描述这个方法适用条件 – 可选)
	 * 
	 * @param data
	 * @return List<CargoInfo>
	 * @exception
	 * @since 1.0.0
	 */
	public static List<TruckInfo> parserTruckList(String data) {
		try {
			JSONObject obj = new JSONObject(data);
			JSONArray array = obj.getJSONArray("truckInfoList");
			List<TruckInfo> infos = JsonUtil.getList(array.toString(),
					TruckInfo.class);
			return infos;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return new ArrayList<TruckInfo>();
	}

	/**
	 * 货源详情
	 * 
	 * @param data
	 * @return
	 * @throws JSONException
	 */
	public static TruckInfo parserTruckInfo(String data) {
		try {
			// JSONObject obj = new JSONObject(data);
			// String info=obj.getString("info");
			TruckInfo infos = JsonUtil.fromJson(data, TruckInfo.class);
			return infos;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new TruckInfo();
	}

}
